package santiago.view.menu;

import santiago.client.Client;
import santiago.view.SantiagoFrame;
import santiago.view.SantiagoValidation;

public class FrameConnection extends SantiagoFrame {

    /**
     * Creates new form FrameConnection
     */
    public FrameConnection() {
        super();
        initComponents();
        TextFieldLogin.setText("" + ((int) (Math.random() * 1000000)));
        setLocationRelativeTo(null);
    }

    @Override
    public void refresh() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabelLogin = new javax.swing.JLabel();
        LabelPassword = new javax.swing.JLabel();
        TextFieldPassword = new javax.swing.JPasswordField();
        ButtonConnection = new javax.swing.JButton();
        TextFieldLogin = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Connexion");
        setMinimumSize(new java.awt.Dimension(400, 200));
        setResizable(false);

        LabelLogin.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelLogin.setText("Nom utilisateur");

        LabelPassword.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelPassword.setText("Mot de passe");

        TextFieldPassword.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        TextFieldPassword.setText("12345678");

        ButtonConnection.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        ButtonConnection.setForeground(new java.awt.Color(179, 96, 74));
        ButtonConnection.setText("Connexion");
        ButtonConnection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonConnectionActionPerformed(evt);
            }
        });

        TextFieldLogin.setFont(new java.awt.Font("Lucida Sans", 0, 14)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Lucida Sans", 0, 11)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 153, 204));
        jLabel1.setText("Créer un compte");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(LabelLogin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(TextFieldLogin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 230, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(LabelPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(TextFieldPassword)
                            .add(layout.createSequentialGroup()
                                .add(ButtonConnection)
                                .add(18, 18, 18)
                                .add(jLabel1)
                                .add(0, 0, Short.MAX_VALUE)))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(28, 28, 28)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(TextFieldLogin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(LabelLogin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(TextFieldPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(LabelPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(28, 28, 28)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(ButtonConnection, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        setSize(new java.awt.Dimension(425, 210));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void ButtonConnectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonConnectionActionPerformed
        if (SantiagoValidation.checkEmptyField(TextFieldLogin.getText())) {
            Client.authentication(TextFieldLogin.getText(), TextFieldPassword.getPassword() + "");
        }
    }//GEN-LAST:event_ButtonConnectionActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonConnection;
    private javax.swing.JLabel LabelLogin;
    private javax.swing.JLabel LabelPassword;
    private javax.swing.JTextField TextFieldLogin;
    private javax.swing.JPasswordField TextFieldPassword;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
